package org.dairy.farms.nandana.core.logic;

import ch.lambdaj.Lambda;
import org.dairy.farms.model.*;
import org.dairy.farms.nandana.web.view.LivestockExpenseToRevenueView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: gduggirala
 * Date: 25/2/13
 * Time: 5:55 PM
 */
@Service(value = "reportsManagementLogic")
public class ReportsManagementLogicImpl implements ReportsManagementLogic {
    /*@Autowired
    ExpenseManagementLogic expenseManagementLogic;
    @Autowired
    RevenueManagementLogic revenueManagementLogic;*/

    @Override
    public List<LivestockExpenseToRevenueView> getExpenseToRevenueReport(Long livestockId) {
        //Map<String, List> returnMap = new HashMap<String, List>();
        List<LivestockExpenseToRevenueView> livestockExpenseToRevenueViewList = new ArrayList<LivestockExpenseToRevenueView>();
        /*List<Expense> expenseList = expenseManagementLogic.getLivestockExpenses(livestockId);
        List<Revenue> revenueList = revenueManagementLogic.getLivestockRevenue(livestockId);
        returnMap.put(EXPENSE_LIST, expenseList);
        returnMap.put(REVENUE_LIST, revenueList);
        for (Expense livestockExpense : expenseList) {
            LivestockExpenseToRevenueView livestockExpenseToRevenueView = new LivestockExpenseToRevenueView();
            livestockExpenseToRevenueView.setLivestockId(livestockId);
            livestockExpenseToRevenueView.setExpenseId(livestockExpense.getId());
            livestockExpenseToRevenueView.setExpenseName(livestockExpense.getExpenseType().getName());
            livestockExpenseToRevenueView.setExpenseAmount(livestockExpense.getAmount());
            livestockExpenseToRevenueView.setNotesExpense(Lambda.extract(livestockExpense.getExpenseNotes(), Lambda.on(ExpenseNotes.class).getId()));
            livestockExpenseToRevenueView.setExpenseDate(livestockExpense.getPaymentDate());
            livestockExpenseToRevenueViewList.add(livestockExpenseToRevenueView);
        }
        for (Revenue revenue : revenueList) {
            LivestockExpenseToRevenueView livestockExpenseToRevenueView = new LivestockExpenseToRevenueView();
            livestockExpenseToRevenueView.setRevenueId(revenue.getId());
            livestockExpenseToRevenueView.setLivestockId(livestockId);
            livestockExpenseToRevenueView.setRevenueName(revenue.getRevenueType().getName());
            livestockExpenseToRevenueView.setRevenueAmount(revenue.getAmount());
            livestockExpenseToRevenueView.setNotesRevenue(Lambda.extract(revenue.getRevenueNotes(), Lambda.on(RevenueNotes.class).getId()));
            livestockExpenseToRevenueView.setRevenueDate(revenue.getPaymentDate());
            livestockExpenseToRevenueViewList.add(livestockExpenseToRevenueView);
        }*/
        return livestockExpenseToRevenueViewList;
    }
}
